#!/bin/bash
#
# Copyright 2015-2017 Adrian DC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# === Uploads Credentials for BasketBuild ===
function __shtools_credentials_basketbuild()
{
  # Usage: __shtools_credentials_basketbuild (Credentials for BasketBuild server)

  # BasketBuild Upload Credentials
  export FTPUploadUserUrl='basketbuild.com';
  export FTPUploadUserName='username.basketbuild.com';
  export FTPUploadPassword=;
  export FTPUploadPath=;

  # Create  .bash_android.uploadftp.basketbuild.rc with the exports to override the credentials
  source "${ANDROID_DEVELOPMENT_SHELL_TOOLS_WORKSPACE:-${HOME}}/.bash_android.uploadftp.basketbuild.rc";

  # Check missing credentials
  [ ! "${FTPUploadUserName}" = 'username.basketbuild.com' ];
}

# === File Uploader BasketBuild ===
function uploadbasketbuild()
{
  # Usage
  if [ -z "${1}" ]; then
    echo '';
    echo ' Usage: uploadbasketbuild <file_path> [target_folder] (File to BasketBuild server uploader)';
    echo '';
    return;
  fi;

  # BasketBuild Uploads Credentials
  if ! __shtools_credentials_basketbuild; then
    >&2 echo '';
    >&2 echo ' uploadbasketbuild: Open android_uploads_basketbuild.rc to see how to set your logins';
    >&2 echo '';
    return;
  fi;

  # Upload file to target with FTP
  uploadftp "${1}" "${2}" 'basketbuild';
}

# === File Downloader BasketBuild ===
function downloadbasketbuild()
{
  # Usage
  if [ -z "${1}" ]; then
    echo '';
    echo ' Usage: downloadbasketbuild <remote_path> (Download from BasketBuild)';
    echo '';
    return;
  fi;

  # BasketBuild Uploads Credentials
  if ! __shtools_credentials_basketbuild; then
    >&2 echo '';
    >&2 echo ' downloadbasketbuild: Open android_uploads_basketbuild.rc to see how to set your logins';
    >&2 echo '';
    return;
  fi;

  # Download file to target with FTP
  downloadftp "${1}" 'basketbuild';
}

# === Private Uploader BasketBuild ===
function uploadprivatebasketbuild()
{
  # Usage
  if [ -z "${1}" ]; then
    echo '';
    echo ' Usage: uploadprivatebasketbuild <device_name> (Upload to private BasketBuild)';
    echo '';
    return;
  fi;

  # File upload to Private
  uploadbasketbuild "${1}" '.private';
}

# === Folder Syncer BasketBuild ===
function syncbasketbuild()
{
  # Usage
  if [ -z "${1}" ] || [ -z "${3}" ]; then
    echo '';
    echo ' Usage: syncbasketbuild <local_path> <remote_path> <--download/--upload> (Folder with BasketBuild server syncer)';
    echo '';
    return;
  fi;

  # BasketBuild Uploads Credentials
  if ! __shtools_credentials_basketbuild; then
    >&2 echo '';
    >&2 echo ' syncbasketbuild: Open android_uploads_basketbuild.rc to see how to set your logins';
    >&2 echo '';
    return;
  fi;

  # Upload file to target with FTP
  syncftp "${1}" "${2}" "${3}" 'basketbuild';
}
